import java.util.Scanner;

/**
 * @author gao
 * @date 2025/8/7 11:40
 */

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            System.out.println(waterProblem(n));
        }
    }

    public static int waterProblem(int n) {
        while (n >= 10) {
            int sum = 0;
            while (n > 0) {
                sum += n % 10;
                n /= 10;
            }
            n = sum;
        }
        return n;
    }
}